import path from "path";
import { defineConfig } from "vite";
import { resolve } from "path";
import vue from "@vitejs/plugin-vue";
import Icons from 'unplugin-icons/vite';
import Components from "unplugin-vue-components/vite";
import { VantResolver } from "unplugin-vue-components/resolvers";
import IconsResolver from "unplugin-icons/resolver";
// https://vitejs.dev/config/
const pathSrc = path.resolve(process.cwd(), "src");
export default defineConfig({
  base: "",
  server: {
    host: true,
  },
  resolve: {
    alias: [
      // /@/xxxx => src/xxxx
      {
        find: /@\//,
        replacement: pathResolve("src") + "/",
      },
    ],
  },
  plugins: [
    vue(),
    Icons({
      autoInstall: true,
    }),
    Components({
      globs: ["src/components/*.{vue}"],
      resolvers: [
        // Auto register icon components
        // 自动注册图标组件
        IconsResolver({
          prefix: "Icon",
        }),

        VantResolver(),
      ],
      dts: path.resolve(pathSrc, "components.d.ts"),
    }),
  ],
});
function pathResolve(dir: string) {
  return resolve(process.cwd(), ".", dir);
}
